package com.puchi.sdkdemo.dialog

import android.app.Activity
import android.content.Context
import android.content.DialogInterface

import android.view.LayoutInflater
import android.view.View
import android.widget.*


import com.orhanobut.logger.Logger

import com.puchi.sdkdemo.R

import com.zalyyh.advertisement.interfac.AdverCallback
import com.zalyyh.advertisement.open.Adavert


class AdvertDialog : RxDialog {
    var advert: FrameLayout? = null
    var activity: Activity? = null


    constructor(context: Context, themeResId: Int) : super(context, themeResId) {
        initView()
    }

    constructor(
        context: Context,
        cancelable: Boolean,
        cancelListener: DialogInterface.OnCancelListener
    ) : super(context, cancelable, cancelListener) {
        initView()
    }

    constructor(context: Context, activity: Activity) : super(context) {
        this.activity = activity
        initView()
    }

    constructor(context: Context, alpha: Float, gravity: Int) : super(context, alpha, gravity) {
        initView()
    }

    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.advert_dialog, null)




        advert = dialogView.findViewById(R.id.advert)
        setView()
        setContentView(dialogView)

    }


    private fun setView() {
        var a = Adavert(activity!!,object : AdverCallback(){
            override fun onError(var1: Int, var2: String) {
                Logger.d(var2)
            }

            override fun onRenderSuccess(var1: View, var2: Float, var3: Float) {
                advert!!.removeAllViews()
                advert!!.addView(var1)
            }
        })
        a.show(a.setAdSlot("939505312",500f,600f).build(),0)
    }

}